<?php

class MRedis
{
	/**
	 * 获取投资滚动数据
	 */
	public static function getScrollInvestData($number = 10)
	{
		$data = Yii::app()->cache_new->lrange("IndexScrollInvestListF",0,$number);
		if(!$data)
			return array();
		$result = array();
		foreach($data as $d)
		{
			$d = json_decode($d);
			$result[] = array(
				'mobile' => Helper::mb_substr_replace($d->moblie,'****',3,4),
				'amount' => number_format($d->investMoney,0,'.',''),
				'rate'   => $d->ageInterest.'%',
			);
		}
		return $result;
	}
	/**
	 * 获取平台总投资额
	 */
	public static function getPlatformInvestedTotal()
	{
		return Yii::app()->cache2->get('PlatformInvestedAmountTotal');
	}
	/**
	 *  获取平台总注册人数
	 */
	public static function getPlatformRegistersTotal()
	{
		return Yii::app()->cache_php->get('TotalRegisterUser');
	}
	/**
	 * 获取已还款项目数和已还款金额
	 */
	public static function getRepaymentInfo()
	{
		$pipeline = Yii::app()->cache_new->pipeline();
		$pipeline->hget('totalSummary','finished_project_count');
		$pipeline->hget('totalSummary','finished_project_amount');
		$pipeline->hget('totalSummary','total_soldOut_count');
		$result = $pipeline->exec();
		return array(
			'count'  => $result[0],//已还款项目数量
			'amount' => $result[1],//已还款项目金额
			'count2' => $result[2],//已售罄项目数量
		);
	}
	/**
	 * 获取用户的投资笔数
	 */
	public static function getUserInvestedNum($userId)
	{
		$pipeline = Yii::app()->cache_ext->pipeline();
		$pipeline->hget($userId.'.Capital','investingCount');
		$pipeline->hget($userId.'.Capital','settleAccountedCount');
		$result   = $pipeline->exec();
		return array_sum($result);
	}
	/**
	 * 获取e钱包的信息配置
	 */
	public static function getEconfig()
	{
		$config = Yii::app()->cache_php->hget('MOBILE_APP_CONFIG','e');
		if($config)
		{
			$config = json_decode($config);
			return $config;
		}
	}
}